home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / prohp1.zip / DPUBLISH.PRG < prev    next >
Text File  |  1992-11-01  |  11KB  |  303 lines

  1. /*
  2.   ┌─────────────────────────────────────────────────────────────────────────┐
  3.   │                                                                         │
  4.   │    Program : publish.prg                                                │
  5.   │                                                                         │
  6.   │    Purpose : To demonstrate the use of text manipulation.               │
  7.   │                                                                         │
  8.   │   Author  : Copyright (C) 1992, I.L.A.,Inc. All Rights reserved.        │
  9.   │                                                                         │
  10.   │   Comments: This source code may be distributed and used freely         │
  11.   │             provided that the copyright notice is not removed.          │
  12.   │                                                                         │
  13.   └─────────────────────────────────────────────────────────────────────────┘
  14.  
  15.   Here's how to get the most out of cursor positioning and text manipulating
  16.   tricks.
  17.   Run the program first. After getting the output, follow the program flow
  18.   and study it. Change margins (lm,rm) and nTextColH and see how
  19.   the program fits text to the new measures.
  20.  
  21.   NOTE: This uses only fixed spacing fonts. You may modify this program
  22.   for use with proportional spacing soft fonts. Simply convert all
  23.   row col coordinates to inches and replace the mlcount() and LQOUT() functions.
  24.  
  25. */
  26. #include "prohp.ch"
  27.  
  28. proc main()
  29. Local lm := 5, rm := 38, nTextColH , nTopM, nVpos, nLp
  30. Local nT,nDayPos,dDate,aMo,nDayBoxLW,aCal,HPCcal:=""
  31. Local nDayT,nDayL,nDayH,nDayW,aMsg,i
  32. Local aData := {{100,1,"January"},;
  33.                 {400,2,"February"},;
  34.                 {372,3,"March"},;
  35.                 {50,4,"April"},;
  36.                 {210,5,"May"},;
  37.                 {400,2,"June"},;
  38.                 {372,3,"July"},;
  39.                 {50,4,"August"},;
  40.                 {210,5,"September"},;
  41.                 {372,3,"October"},;
  42.                 {50,4,"November"},;
  43.                 {350,6,"December"}}
  44. // the next line defines a block to calculate the current line width in Inches.
  45. Local bPageW:= {||HP_data(D_RMI)-HP_data(D_LMI)}
  46.  
  47. // same as above, but the result is in columns.
  48. Local bWidth:= {||(HP_data(D_RMI)-HP_data(D_LMI))*HP_data(D_CPI)}
  49. Local bVpos:= {|l|l/HP_data(D_LPI)}
  50. Local cText:="* The legitimate object of government is to do for a "+;
  51.         "community of people whatever they need to have done, but "+;
  52.         "cannot do at all in their separate and individual capacities. "+;
  53.         chr(13)+chr(10)+"- Abraham Lincoln (1809-1865)"
  54.  
  55. //  Remove the next comment marks and recompile to see how ProHP is helping
  56. //   you save time and code with its flexibility.
  57.  
  58. /*
  59. cText+=chr(13)+chr(10)+"* Voters quickly forget what a man says."+;
  60.         "-Richard M. Nixon"
  61. cText+=chr(13)+chr(10)+"* Whenever any Form of Government becomes destructive ..."+;
  62.         " it is the Right of the people to alter or abolish it.-"+;
  63.         "The Declaration of Independance."
  64. */
  65. HP_init()
  66. HP_send(.t.)
  67. set2print("dpublish.hpc")
  68. HP_reset()
  69. HP_pitch(10,ITALIC)     // courier 10, Italic
  70. HP_lpi(6)
  71. nTopM := lqout(cText,eval(bWidth))         // print the text
  72.  
  73. // Set top margin to the number of lines used by cText +1.
  74. nTopM+=(0.5*HP_data(D_LPI))+1
  75.  
  76. // set Text Column Height to 30 lines and convert it to Inches.
  77.  HP_tmset(nTopM)
  78.  HP_rcpos(0,0)
  79.  HP_rline(0.01,eval(bPageW))     // draw line
  80. nTextColH := 40 / HP_data(D_LPI)        // make text col length to 40 lines
  81.  
  82.  HP_lmset(lm)            // set Left Margin
  83.  HP_rline(nTextColH,0.01)        // print vertical line at left margin
  84.  HP_rmset(rm)            // set Right margin
  85.  HP_rcpos(,rm)           // move cursor to right margin at the current row
  86.  HP_rline(nTextColH,0.01)        // draw vertical line at cursor pos.
  87.  HP_rcpos(0,lm)          // move to top line, left margin
  88. // fill the area between the margins with gray shade.
  89.  HP_BAR(nTextColH,HPcol2i(rm-lm),GFILLGRAY,2)
  90. nLp := lqout(cText)      // print the text
  91.  HP_rcpos(1,,.t.)        // move one line down
  92. nLp++
  93. // go to Left Margin (inch coordinates). We did not use Row Col. coordinates
  94. // because font pitch will change the margin reference.
  95.  HP_setpos(,HP_data(D_LMI))
  96.  HP_rline(0.01,eval(bPageW))     // draw line across the text col width
  97. // will draw a graph here to the end of column
  98. HP_data(D_SHADOWTYPE,9)
  99. Graphr(nTextColH-((nLp+1)/HP_data(D_LPI)),eval(bPageW),aData)
  100.  
  101. // Now we create the next text column
  102. lm:=rm+2        // set new left margin to prev. Right margin + 2 columns.
  103. rm:=75          // set Right margin
  104.  HP_clrmrg()     // clear margin
  105.  HP_rcpos(0,0)   // cursor to 0,0
  106.  HP_lmset(lm)    // set LM
  107.  HP_rmset(rm)    // set RM
  108.  HP_rcpos(0,lm)  // Cursor to top row , LM
  109. // draw gray shaded area over the defined text column
  110.  HP_BAR(nTextColH,HPcol2i(rm-lm),GFILLGRAY,10)
  111. // print the text
  112. /*
  113. nLp := lqout(cText)
  114.  HP_rcpos(1,,.t.)        // one line down
  115. nLp++
  116.  HP_rcpos(,lm)           // and go to left margin
  117.  HP_rline(0.01,eval(bPageW))     // draw line
  118. nVpos := eval(bVpos,nLp)        // find Vertical position of cursor
  119. */
  120. nVpos:=0
  121.  HP_pitch(12)    // courier 12 , If your printer does not support 12 Pitch
  122.                 // you may get wider text col and the calculation of
  123.                 // LMI will not be accurate. So check printer before using.
  124. nLp:=lqout(cText)
  125.  HP_rcpos(1,,.t.)
  126. nLp++
  127.  HP_setpos(,HP_data(D_LMI))
  128.  HP_rline(0.01,eval(bPageW))
  129. nVpos += eval(bVpos,nLp)        // continue tracking Vertical Cursor pos.
  130.  HP_pitch(16)
  131.  HP_lpi(8)
  132. nLp:=lqout(cText)
  133.  HP_rcpos(1,,.t.)
  134. nLp++   //
  135.  HP_setpos(,HP_data(D_LMI))      // Go to left margin
  136.  HP_rline(0.01,eval(bPageW))     // draw separator line
  137. nLp++
  138. nVpos += eval(bVpos,nLp)        // calc current vertical pos
  139.  
  140. // now draw this month calendar
  141. aCal:=HPdrawmonth(Date(),nVpos,HP_data(D_LMI),nTextColH-nVpos,eval(bPageW))
  142. aMo:=aCal[2]
  143. HPCcal:=aCal[1]
  144. // qqout(HPCcal)
  145. // mark todays date
  146. dDate:=date()
  147. // find where month starts
  148. nT:=dow(ctod(str(month(dDate),2)+'/01/'+str(year(dDate),4)))
  149. // fix the desired box pos
  150. nDayPos:=nT+day(dDate)-1
  151. nDayBoxLW:=0.05
  152. // draw a box surrounding the day box
  153.  HP_box(aMo[nDayPos,1],aMo[nDayPos,2],aMo[8,1]-aMo[1,1]-nDayBoxLW,;
  154. aMo[2,2]-aMo[1,2]-nDayBoxLW,nDayBoxLW,GFILLBLACK)
  155. // mark todays date
  156. dDate:=date()
  157. // find where month starts
  158. nT:=dow(ctod(str(month(dDate),2)+'/01/'+str(year(dDate),4)))
  159. // fix the desired box pos
  160. nDayPos:=nT+day(dDate)-1
  161.  
  162. // draw a box surrounding the day box
  163. nDayBoxLW:=0.03 // width of line to draw box
  164. nDayT:=aMo[nDayPos,1]   // top coordinate for date box
  165. nDayL:=aMo[nDayPos,2]   // left
  166. nDayH:=aMo[8,1]-aMo[1,1]-nDayBoxLW  // height of box
  167. nDayW:=aMo[2,2]-aMo[1,2]-nDayBoxLW  // Width
  168. HP_box(nDayT,nDayL,nDayH,nDayW,nDayBoxLW,GFILLBLACK) // draw the box
  169. // now we will print inside the box
  170.  HP_pitch(16) // small pitch here
  171.  HP_lpi(8)       // set LPI to 8
  172. aMsg := {"ProHP","Day"} // message array
  173. // and this is very nice
  174.  HP_aatsay(nDayT+nDayH-HProw2i(len(aMsg)+1),nDayL+nDayW/2,aMsg,,"C")
  175.  
  176.  HP_clrmrg()
  177.  
  178. // set a new top margin for this page by adding the current Top Margin Inch
  179. // to the text length.
  180. // ProHP keep track on the the margins settings and stores it in HP_data()
  181. // at D_TMI we have the current Top Margin in Inch
  182.  HP_tmset((HP_data(D_TMI)+nTextColH) * HP_data(D_LPI)+1)
  183.  HP_rcpos(0,0)
  184.  HP_rline(0.01,eval(bPageW))
  185.  HP_pitch(10)
  186.  HP_lpi(6)
  187.  HP_BAR( (mlcount(cText,eval(bWidth))+1) / HP_data(D_LPI),;
  188.         HPcol2i(eval(bWidth)),GFILLGRAY,20)
  189.  lqout(cText)
  190.  
  191.  HP_rcpos(1,,.t.)
  192.  HP_setpos(,HP_data(D_LMI))
  193.  HP_rline(0.01,eval(bPageW))
  194. qout()
  195. HP_pitch(16,1)
  196. cText:= [***]+Chr(13)+CHR(10)+;
  197.         [Font and shading changes are a snap. This is a great ]+;
  198.         [example of how to fit text to columns. Select the font and ]+;
  199.         [column width, and ProHP will break the lines for you. ]+;
  200.         [The calendar was then placed into the remaining column area. ]+;
  201.         [We did this without having to define specific coordinates!]+;
  202.         chr(13)+chr(10)+;
  203.         [Check out 'DPUBLISH.PRG' to see how simple it is to perfectly center ]+;
  204.         [text in the Nov 12 Date box!  You'll love it.]
  205.  
  206. lqout(cText,7*HP_data(D_CPI))
  207.  
  208.  HP_reset()
  209. set2screen()
  210. return
  211.  
  212. Function lqout(cStr,nWidth)
  213. Local nTotLines, crlf := CHR(13)+chr(10), cLine, nLine
  214. nWidth := iif(nWidth == NIL,(HP_data(D_RMI)-HP_data(D_LMI))* ;
  215.         HP_data(D_CPI),nWidth)
  216. nTotLines := MLCOUNT(cStr,nWidth)
  217.  
  218. FOR nLine := 1 TO nTotLines
  219.     cLine := MEMOLINE(cStr,nWidth,nLine)
  220.     qout(cLine)
  221. NEXT
  222. return nTotLines
  223.  
  224. FUNCTION graphr(nMaxH,nMaxW,aData)
  225. LOCAL nBarSp := 1, nBarW := 1, nBarH := 1
  226. Local nLw := 0.01  // or HP_data(D_LINEWIDTH)
  227. Local nMaxVal,nBarFactor,i,nPos,nBarLength
  228. Local nOldCpi:=HP_data(D_CPI)
  229.  
  230.  HP_pitch(16,ITALIC)
  231. nBarH := nMaxH/len(aData)
  232. nBarSp := max(nBarH*0.20,2/HP_data(D_LPI))
  233. nBarH:=nBarH-nBarSp-(nBarSp/len(aData))
  234.  
  235. // find maximum value in array
  236. nPos := AMAX(aData)
  237. IF EMPTY(nPos)  // NIL or all zeros
  238.    RETURN .F.
  239. ENDIF
  240. // get the highest value in array
  241. nMaxVal := aData[nPos,1]
  242. /*
  243.   Create a factor for all array elements so their bar length will be
  244.   relative to the longest one. This will fix the length of (Graph Width-
  245.   Shadow width).
  246. */
  247. nBarFactor := (nMaxW-(HP_data(D_SHADOWWIDTH)*2)- ;
  248.               (HP_data(D_LINEWIDTH)*2)) / nMaxVal
  249.  
  250. // draw frame of graph
  251.  HP_rbox(nMaxH,nMaxW,0.02)
  252.  
  253. FOR i:=1 to LEN(aData)
  254.      HP_setpos(nBarSp,,.T.)      // do a little space
  255.     // draw first box
  256.     nBarLength :=aData[i,1]*nBarFactor-HP_data(D_SHADOWWIDTH)
  257.      HP_rbox(nBarH,nBarLength,nLw,GFILLBLACK)
  258.      HP_savecsr()        // save csr pos
  259.      hp_setpos(nLw,,.t.) // move right to start draw after line width
  260.     // draw a bar inside the box
  261.      HP_bar(nBarH-nLw,nBarLength-nLw)
  262.      HP_restcsr()        // restore csr
  263.      HP_savecsr()        // save csr pos
  264.     // print a message for this box and its value, at the top of the box
  265.      HP_atsay(-(0.25/HP_data(D_LPI)),1/HP_data(D_CPI),aData[I,3]+;
  266.         ' ('+ltrim(str(aData[i,1]))+')',.T.)
  267.      HP_restcsr()        // restore csr pos
  268.      HP_setpos(nBarH,,.t.)       // move down nBarH
  269. NEXT
  270.  HP_pitch(nOldCpi)
  271. RETURN ""
  272.  
  273. FUNCTION AMax( aArray )
  274. LOCAL nLen, nPos, expLast, nElement
  275.  
  276.    DO CASE
  277.  
  278.    // Invalid argument
  279.    CASE VALTYPE( aArray ) <> "A"
  280.       RETURN NIL
  281.  
  282.    // Empty argument
  283.    CASE EMPTY( aArray )
  284.       RETURN 0
  285.  
  286.    OTHERWISE
  287.       nLen := LEN( aArray )
  288.       nPos := 1
  289.       expLast := aArray[1,1]
  290.       FOR nElement := 2 TO nLen
  291.          IF aArray[nElement,1] > expLast
  292.             nPos := nElement
  293.             expLast := aArray[nElement,1]
  294.          ENDIF
  295.       NEXT
  296.  
  297.    ENDCASE
  298.  
  299.    RETURN nPos
  300.  
  301.  
  302.  
  303.